
/**
 * @file menuEXE.c
 * @author Sevenfite(sevenfite@163.com)
 * @brief 菜单中的执行函数
 * @version 0.1
 * @date 2023-11-12
 * @note 在这里放菜单中要执行的函数
 * @warning
 * 请不要在这里做卡死处理，否则会导致其他地方的轮询失效，这里的函数都是会被轮询的，所以局部变量有很多是静态的
 * @copyright Copyright (c) 2023
 *
 */

#include "menuEXE.h"

#include "ABS_key.h"
#include "BuildTime.h"
#include "C_code_Log.h"
#include "control.h"
#include "display.h"
#include "globalTime.h"









/// @brief 显示编译时间
/// @param key_Num
/// @return
My_StatusTypeDef buildTime(int key_Num) {
  displayStr(getBuildTime(), Display_firstCol, Display_firstRow, RED);
  displayStr(getBuildDate(), Display_firstCol, Display_secondRow, RED);
  if (key_Num == Key_ESC) {
    return MY_OK;
  }
  return MY_BUSY;
}

/// @brief 进行1号路线的测试
/// @param key_Num
/// @return
My_StatusTypeDef gameDebug(int key_Num) {
  displayStr("gameDebug", Display_firstCol, Display_firstRow, RED);
  if (key_Num == Key_ESC) {
    return MY_OK;
  }
  static uint8_t runTime = 0;
  if (runTime == 0) {
    runTime = 1;
    controlCenterInit(&gl_controlCenter, mapInfo, runMethodTable[0]);
  }
  if (gl_controlCenter.update == MY_READY) {
    LOG_INFO("路段完成");
    controlCenterUpdate(&gl_controlCenter, mapInfo);
  } else if (gl_controlCenter.update == MY_EXIT) {
    LOG_INFO("路线完成");
    runTime = 2;
    return MY_OK;
  } else if (gl_controlCenter.update == MY_Running) {
  }
  if (getGlobalTime() % 10 == 0) {
    findLine_Task(&gl_controlCenter);
    speedUpHandle_Task(&gl_controlCenter);
    roadBlocksHandle_Task(&gl_controlCenter);
    speedUpHandle_Task(&gl_controlCenter);
    seekNodeHandle_Task(&gl_controlCenter);
    carParkHandle_Task(&gl_controlCenter);
    rotateHandle_Task(&gl_controlCenter);
  }
  return MY_BUSY;
}

#include "collisionSwitch.h"
#include "photoelectric.h"
/**
 * @brief 碰撞开关和光电开关测试
 * 
 * @param key_Num 
 * @return My_StatusTypeDef 
 */
My_StatusTypeDef switchTest(int key_Num){
  if (key_Num == Key_ESC) {
    return MY_OK;
  }
  char str[20];
  sprintf(str, "collision:%d", collision_seekFront());
  displayStr(str, Display_firstCol, Display_firstRow, RED);
  sprintf(str, "photoelectric_F:%d", PES_FRONT);
  displayStr(str, Display_firstCol, Display_secondRow, RED);
  sprintf(str, "photoelectric_L:%d", PES_LEFT);
  displayStr(str, Display_firstCol, Display_thirdRow, RED);
  sprintf(str, "photoelectric_R:%d", PES_RIGHT);
  displayStr(str, Display_firstCol, Display_fourthRow, RED);
  return MY_BUSY;
}

#if GAME_MODE == TRAVEL
#include "st7735.h"
void ShowChinese_Platform1_5(uint16_t x,uint16_t y,uint8_t number)
{
  uint8_t point_x = x;
  ST7735_WriteChineseChar(point_x,y,1,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,5,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,4,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,5,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,6,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,number/10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,number%10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,7,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
}
void ShowChinese_Erect_Scenic_Spot(uint16_t x,uint16_t y,uint8_t number)
{
  uint8_t point_x = x;
  ST7735_WriteChineseChar(point_x,y,0,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,1,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,2,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,3,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,number/10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,number%10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,7,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
}
void ShowChinese_Platform6(uint16_t x,uint16_t y,uint8_t number)
{
  uint8_t point_x = x;
  ST7735_WriteChineseChar(point_x,y,6,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,4,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,5,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,6,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,number/10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,number%10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,7,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
}
void ShowChinese_Platform7(uint16_t x,uint16_t y,uint8_t number)
{
  uint8_t point_x = x;
  ST7735_WriteChineseChar(point_x,y,7,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,4,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,5,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,6,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,number/10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,number%10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,7,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
}
void ShowChinese_Platform8(uint16_t x,uint16_t y,uint8_t number)
{
  uint8_t point_x = x;
  ST7735_WriteChineseChar(point_x,y,8,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,4,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,5,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,6,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,number/10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,number%10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,7,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
}
void ShowChinese_backhome(uint16_t x,uint16_t y)
{
  uint8_t point_x = x;
  ST7735_WriteChineseChar(point_x,y,8,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,9,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,2,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,10,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
}
void ShowChinese_FinialSorce(uint16_t x,uint16_t y,uint32_t number)
{
  uint8_t point_x = x;
  ST7735_WriteChineseChar(point_x,y,11,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,12,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese.width,y,number/10000%10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,number/1000%10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,number/100%10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,number/10%10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,11,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,number%10,Font_Chinese_Num,ST7735_WHITE,ST7735_BLACK);
  ST7735_WriteChineseChar(point_x+=Font_Chinese_Num.width,y,12,Font_Chinese,ST7735_WHITE,ST7735_BLACK);
}
void ShowFinial(uint8_t upright_scenic_spot,uint8_t platform_1_5,
                uint8_t platform_6,uint8_t platform_7,uint8_t platform_8)
{
  char str[9];
  displayStr("erect scenic spot", Display_firstCol, Display_firstRow, RED);
  sprintf(str,"%d",upright_scenic_spot);
  displayStr(str, Display_firstCol, Display_secondRow,RED);
  displayStr("platform 1_5", Display_firstCol, Display_thirdRow, RED);
  sprintf(str,"%d",platform_1_5);
  displayStr(str, Display_firstCol, Display_fourthRow,RED);
  displayStr("platform 6", Display_firstCol, Display_fifthRow, RED);
  sprintf(str,"%d",platform_6);
  displayStr(str, Display_firstCol, Display_fifthRow+Display_spaced,RED);
  displayStr("platform 7", Display_firstCol, Display_fifthRow+Display_spaced*2, RED);
  sprintf(str,"%d",platform_7);
  displayStr(str, Display_firstCol, Display_fifthRow+Display_spaced*3,RED);
  displayStr("platform 8", Display_firstCol, Display_fifthRow+Display_spaced*4, RED);
  sprintf(str,"%d",platform_8);
  displayStr(str, Display_firstCol, Display_fifthRow+Display_spaced*5,RED);
  displayStr("go home", Display_firstCol, Display_fifthRow+Display_spaced*6, RED);
  displayStr("2", Display_firstCol, Display_fifthRow+Display_spaced*7, RED);
  displayStr("Total score", Display_firstCol, Display_fifthRow+Display_spaced*8, RED);
  uint16_t score = upright_scenic_spot*11+platform_1_5*15+platform_6*60+platform_7*90+platform_8*150;
  sprintf(str,"%f",score+score*0.5);
  displayStr(str, Display_firstCol, Display_fifthRow+Display_spaced*9, RED);
}
void ShowFinialChinese(uint8_t upright_scenic_spot,uint8_t platform_1_5,
                uint8_t platform_6,uint8_t platform_7,uint8_t platform_8)
{
  ShowChinese_Erect_Scenic_Spot(Display_firstCol,Font_Chinese.height*0,upright_scenic_spot);
  ShowChinese_Platform1_5(Display_firstCol,Font_Chinese.height*1,platform_1_5);
  ShowChinese_Platform6(Display_firstCol,Font_Chinese.height*2,platform_6);
  ShowChinese_Platform7(Display_firstCol,Font_Chinese.height*3,platform_7);
  ShowChinese_Platform8(Display_firstCol,Font_Chinese.height*4,platform_8);
  ShowChinese_backhome(Display_firstCol,Font_Chinese.height*5);
  uint16_t score = upright_scenic_spot*11+platform_1_5*15+platform_6*60+platform_7*90+platform_8*150;
  ShowChinese_FinialSorce(Display_firstCol,Font_Chinese.height*6,(score+score*0.5)*10);
}
#endif
My_StatusTypeDef ChineseTest(int key_Num){
  if (key_Num == Key_ESC) {
    return MY_OK;
  }
#if GAME_MODE == TRAVEL
  ShowFinialChinese(4,10,0,2,2);
#endif
#if GAME_MODE == FIND_TREASURE
  displayStr("you are FIND_TREASURE,not need Chinese",Display_firstCol,Display_firstRow,RED);
#endif
  return MY_BUSY;
}
